package com.erpoa.controller;

import cn.hutool.json.JSONUtil;
import com.erpoa.constants.MqConstant;
import com.erpoa.entity.LogicBean;
import com.erpoa.service.MsgService;
import com.erpoa.utils.FastJsonUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


@CrossOrigin(maxAge = 3600)
@Api(value = "RabbitMQController", tags = {"mq测试"})
@RestController
@RequestMapping("/mq")
public class RabbitMQController {


    @Autowired
    private MsgService msgService;


    @GetMapping("sendMsg")
    @ApiOperation("延时队列test")
    public String sendMsg() {

        for (int i = 0; i <= 1045; i++) {
            //  System.out.println("线程:" + Thread.currentThread().getId() +"发送延时消息时间:" + DateUtils.getTime() + i + "hj");
            LogicBean logicBean = new LogicBean();
            logicBean.setTrayNumber(i + "hj");

            msgService.sendDelayMsgToMQ(MqConstant.SYS_ORDER_DELAY_EXCHANGE, MqConstant.SYS_ORDER_DELAY_KEY, FastJsonUtils.getBeanToJson(logicBean), 54);//30秒钟后执行

        }
        LogicBean logicBean = new LogicBean();
        logicBean.setTrayNumber("5646465");

        msgService.sendDelayMsgToMQ(MqConstant.SYS_ORDER_DELAY_EXCHANGE, MqConstant.SYS_ORDER_DELAY_KEY, FastJsonUtils.getBeanToJson(logicBean), 54);//30秒钟后执行
        return JSONUtil.toJsonStr("发送延时消息成功" + new Date());
    }
}
